home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4889 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: nova.umuc.edu!nova!ldigiova
  2. From: Larry DiGiovanni <ldigiova@nova.umuc.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Arrays of strings
  5. Date: Wed, 7 Feb 1996 14:23:19 -0500
  6. Organization: University of Maryland University College
  7. Message-ID: <Pine.SOL.3.91.960207141605.27357A-100000@nova>
  8. NNTP-Posting-Host: nova.umuc.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11. X-Sender: ldigiova@nova
  12.  
  13.  
  14. I'm trying to read lines of a text file and load those lines into an 
  15. array.  I have a couple of questions...
  16.  
  17. 1.  How do I declare the array to contain the text.  When it is declared, 
  18. I will not know how many lines are in the text file.  char **txtarray?
  19.  
  20. 2.  How do I allocate the space for the data once I know how many lines 
  21. are in the text file?  txtarray = malloc((size_t)(nelements))?
  22.  
  23. 3.  What is the best way to read from the text file into the array 
  24. elements? fscanf? fgets?  I have had no success reading directly into the 
  25. elements with these two functions.  I don't understand why, but it may be 
  26. related to my poor understanding of (1) and (2) above as well.
  27.  
  28. Any help would be greatly appreciated.  TIA
  29.  
  30. Larry DiGiovanni
  31.  
  32.